package com.sc.controller.rui;

import com.sc.domain.House;
import com.sc.dto.HousePageDto;
import com.sc.result.Result;
import com.sc.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @Description:
 * @Author: Rui
 * @Date: 2024/11/25 9:30
 */
@RestController
@RequestMapping("house")
@CrossOrigin
public class HouseController {
    @Autowired
    private HouseService houseService;
//    添加房屋
    @PostMapping("addHouse")
    public Result add(@RequestBody House house) {
        return  Result.success("添加成功",houseService.add(house));
    }
//    根据id删除房屋
    @DeleteMapping("deleteHouse/{id}")
    public Result deleteHouse(@PathVariable Integer id) {

        return  Result.success("删除成功",houseService.deleteHouse(id));
    }
//    编辑房屋
    @PostMapping("updateHouse")
    public Result updateHouse(@RequestBody House house) {
        return  Result.success("修改成功",houseService.updateHouse(house));
    }
//    根据id来查找房屋
    @GetMapping("selectById")
    public Result selectById(Integer id) {
        return  Result.success("查询成功",houseService.selectById(id));
    }

//    分页查询和模糊查询结合
    @PostMapping("pageQuery")
    public Result pageQuery(@RequestBody  HousePageDto housePageDto) {
        return  Result.success("查询成功",houseService.pageQuery(housePageDto));
    }
//    批量删除
    @DeleteMapping("deleteHouseByIds")
    public Result deleteHouseByIds( @RequestBody List<Integer> ids) {
        return  Result.success("删除成功",houseService.deleteHouseByIds(ids));
    }

}
